package com.dk.controller;

import com.dk.config.DyDatasource;
import com.dk.pojo.User;
import com.dk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zh
 * @Description TODO
 * @createTime 2023/11/23
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/select")
    public List<User> select(){
        //耦合度过高
//        DyDatasource.t.set("ds1");
        List<User> users = userService.selectUser();
        return users;
    }


    @GetMapping("/insert")
    public String insertUser(){
        //耦合度过高
//        DyDatasource.t.set("ds2");
        User user = new User();
        user.setUsername("aaa");
        user.setPassword("1234");
        userService.insertUser(user);
        return "ok";
    }

}
